﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DailyComics.Common.Model.Storage;
using System.Windows.Media;

namespace DailyComics.Common.Model.ImageProvideStrategies
{
  public abstract class CachingImageProviderStrategy : IImageProviderStrategy
  {
    private IStorage storage;

    public CachingImageProviderStrategy(IStorage storage)
    {
      this.storage = storage;
    }

    #region IImageProviderStrategy Members

    public ImageSource GetImage(DateTime date)
    {
      if (storage.Contains(date)) return storage.Get(date);

      return DoGetImage(date);
    }

    protected abstract ImageSource DoGetImage(DateTime date);

    public bool IsImageAvailable(DateTime date)
    {
      return storage.Contains(date) || DoIsImageAvailable(date);
    }

    protected abstract bool DoIsImageAvailable(DateTime date);
    
    #endregion
  }
}
